#region File Description
//  XAEnima 
//  License: GNU/GPL
//  Developer: Federico Leonardo Motta
//  File description: This Screen is used to choose users frequencies
#endregion

#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using XAEnima.Core.GameManager;
using XAEnima.Core.Stimulation.Tipi;
using XAEnima.Core.Stimulation.External;
using PCClient_DLL_1_0;
#endregion



namespace XAEnima.Core.Screens.Domotica
{
    public delegate void EnvAction();
    public class Ambiente : Microsoft.Xna.Framework.DrawableGameComponent
    {
        Texture2D lamp;
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        bool OldState = false;
        float screenscale;
        Rectangle area;
        Matrix SpriteScale;
        IInputManager InputManagerService;
        StimulationManager sm;
        IComunicationManager sender;
        SpriteFont font;
        public event EnvAction OnBack;


        public Ambiente(Game game)
            : base(game)
        {
            InputManagerService = (IInputManager)Game.Services.GetService(typeof(IInputManager));
            InputManagerService.EscapeReleased += new PressedEventHandler(XIsPressed);
            sm = new StimulationManager(Game);

            Automation auto = new Automation("127.0.0.1", "80");
           /* Light light = new Light("127.0.0.1", "80");
            light.SwitchOn("luce");
            light.SetLightStatus("luce", "0");*/

        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            screenscale = (float)(Game.GraphicsDevice.Viewport.Width / 1600f);
            spriteBatch = (Game.Services.GetService(typeof(SharedContext)) as SharedContext).sprite_batch;
            area = Game.GraphicsDevice.Viewport.TitleSafeArea;
            float x_pos = (float)Game.GraphicsDevice.Viewport.Width / 2.82f;
            float y_pos = (float)Game.GraphicsDevice.Viewport.Height / 3;
            //      lamp = Game.Content.Load<Texture2D>(@"Domotica/lamp2");
                /*  Light light = new Light("192.68.1.35", "80");
                  light.OpenOWNConnection();
                  light.SetLightStatus("11", "1");
                  light.SetLightStatus("25", "1");*/
            base.Initialize();

        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            //graphics.GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin();
            SpriteFont c = Game.Content.Load<SpriteFont>("Arial");
        //     spriteBatch.Draw(lamp, new Vector2(200,400), null, Color.White, 0f, Vector2.Zero, screenscale, SpriteEffects.None, 0f);
            spriteBatch.End();

            base.Draw(gameTime);
        }


        public void XIsPressed()
        {
            // Return to the main menu.
            if (OnBack != null) { OnBack(); }
        }
    }
}
